// Copyright 2022 Huawei Cloud Computing Technology Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "CaeSocket.h"

void CaeSocket::EventNotice()
{
    if (m_eventNotice == nullptr) {
        return;
    }
    m_eventNotice->Notice(this);
}

void CaeSocket::SetEventNotice(CaeEventNotice *localPEventNotice)
{
    this->m_eventNotice = localPEventNotice;
}

void CaeSocket::SetFd(int localFd)
{
    this->m_fd = localFd;
}

int CaeSocket::GetFd()
{
    return m_fd;
}

void CaeSocket::SetStatus(int localStatus)
{
    this->m_status = localStatus;
}

int CaeSocket::GetStatus()
{
    return m_status;
}

void CaeSocket::SetSocketOption(uint32_t localSocketOption)
{
    this->m_socketOption = localSocketOption;
}

int CaeSocket::GetSocketOption()
{
    return static_cast<int>(m_socketOption);
}

void CaeSocket::SetAddress(uint32_t localRemoteIp, uint16_t localRemotePort, uint32_t localLocalIp,
    uint16_t localLocalPort)
{
    this->m_remoteIp = localRemoteIp;
    this->m_remotePort = localRemotePort;
    this->m_localIp = localLocalIp;
    this->m_localPort = localLocalPort;
}

void CaeSocket::GetAddress(uint32_t *pRemoteIp, uint16_t *pRemotePort, uint32_t *pLocalIp, uint16_t *pLocalPort)
{
    *pRemoteIp = this->m_remoteIp;
    *pRemotePort = this->m_remotePort;
    *pLocalIp = this->m_localIp;
    *pLocalPort = this->m_localPort;
}